package nl.windgazer.arachne.pages;

import java.util.Date;

import nl.windgazer.arachne.annotations.IncludeCufon;
import nl.windgazer.arachne.annotations.IncludeFaceBookOpenGraphInfo;
import nl.windgazer.arachne.annotations.IncludeFontFace;
import nl.windgazer.arachne.components.ExternalSource;
import nl.windgazer.arachne.components.LanguageSwitch;
import nl.windgazer.arachne.components.ZeroClip;
import nl.windgazer.arachne.components.formelements.Captcha;
import nl.windgazer.arachne.components.socialmedia.facebook.FacebookShareLink;
import nl.windgazer.arachne.mixins.CKEditor;
import nl.windgazer.arachne.mixins.MessagesInterceptorTranslator;
import nl.windgazer.arachne.mixins.PopupLink;
import nl.windgazer.arachne.services.ArachnePrivilegesImpl;
import nl.windgazer.arachne.services.facebook.FacebookLikeMediumType;
import nl.windgazer.arachne.util.ArachneSymbolConstants;
import nl.windgazer.arachne.util.FontFaceConstants;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Mixin;
import org.apache.tapestry5.annotations.MixinClasses;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.corelib.components.ActionLink;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.PageLink;
import org.apache.tapestry5.corelib.components.TextArea;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.services.SymbolSource;
import org.apache.tapestry5.services.ComponentClassResolver;
import org.apache.tapestry5.services.Cookies;


/**
 * Test page for some Arachne stuff.
 */
@IncludeFontFace(value=FontFaceConstants.FONTFACE_BPMONO)
@IncludeCufon(value=FontFaceConstants.CUFON_CALIGRAFYFLF, replace="p")
@IncludeFaceBookOpenGraphInfo(title="Just a test for OpenGraph meta-info",type=FacebookLikeMediumType.article,url="",site_name="",image="context:/img/3oc.png",description="message:facebook.desc")
public class Index
{

	//Injects and Persists

	@Inject
	private ComponentClassResolver _ccr;

	@Inject
	private SymbolSource _symbols;

	@Inject
	private Cookies _cookies;

	//Properties and Parameters
	//Components

	@SuppressWarnings("unused")
	@Mixin
	private MessagesInterceptorTranslator _messagesInterceptor;

	@SuppressWarnings("unused")
	@Component(id = "clipping1", parameters = {"target=literal:clipping1","origin=literal:clipping1","clipping=literal:Hellooooooo Nurse!"})
	private ZeroClip _clipping1Component;
	
	@SuppressWarnings("unused")
	@Component(id = "translatorRole", parameters = {})
	private ActionLink _translatorRoleComponent;

	@SuppressWarnings("unused")
	@Component(id = "logoutLink", parameters = {})
	private ActionLink _logoutLinkComponent;

	@SuppressWarnings("unused")
	@Component(id = "testLink", parameters = { "page=prop:testLink" })
	@MixinClasses(PopupLink.class)
	private PageLink _testLink;

		public String getTestLink() {
			return _ccr.resolvePageClassNameToPageName(Index.class.getName());
		}

	@SuppressWarnings("unused")
	@Component(id = "testForm", parameters = {})
	private Form _testFormComponent;

	@SuppressWarnings("unused")
	@Component(id = "captchaTest", parameters = {"label=message:captchaLabel"})
	private Captcha _captchaTestComponent;

	@SuppressWarnings("unused")
	@Component(id = "intro", parameters = {"uid=intro"})
	private ExternalSource introManagedContent;

	@SuppressWarnings("unused")
	@Component(id = "localeSwitch", parameters = {})
	private LanguageSwitch _localeSwitchComponent;
	
//	@SuppressWarnings("unused")
//	@Component(id = "fbShare", parameters = {"fbtitle=A title for facebook","fbdesc=A description for facebook"})
//	private FacebookShareLink _fbShareComponent;

	@SuppressWarnings("unused")
	@Component(id = "ckeditortest", parameters = {})
	@MixinClasses(value=CKEditor.class)
	private TextArea _ckeditortestComponent;

	//Events

	@OnEvent(component="translatorRole", value=EventConstants.ACTION)
	Object addTranslatorRole() {
		ArachnePrivilegesImpl.setRole(_symbols.valueForSymbol(ArachneSymbolConstants.TRANSLATOR_ROLE), _cookies);
		return Index.class;
	}

	@OnEvent(component="logoutLink", value=EventConstants.ACTION)
	Object removeCookieLogin() {
		ArachnePrivilegesImpl.logout(_cookies);
		return Index.class;
	}

	//Other (check for business-logic, it should not remain here)

	public Date getCurrentTime() 
	{ 
		return new Date(); 
	}

	public String getCKTest() {
		return "CKEditor Testing";
	}

	public void setCKTest(String test) {
		//Ignore
	}
}
